<%--
  Created by IntelliJ IDEA.
  User: asus
  Date: 2023/5/6
  Time: 14:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>跳转测试，后端请求数据</title>
    <script src="../js/axios.js"></script>
</head>
<body>
<p1>这是d页面</p1>
<button>无真实路径点击向后端请求数据</button>
<button>有真实路径点击向后端请求数据</button>
</body>
<script>
    const btn = document.querySelectorAll("button");
    btn[0].addEventListener("click",function () {
        axios.get("/givedata").then(result=>{
            console.log("d0中获取的数据:"+result.data)
        })
    })
    btn[1].addEventListener("click",function () {
        axios.get("${pageContext.request.contextPath}/givedata").then(result=>{
            //可以正常获取数据，问题出在打印上
            console.log("d1中获取的result:"+result);
            console.log("d1调用json方法解析:"+JSON.stringify(result.data))
        })
    })
</script>
</html>
